package com.gxa.controller;

import com.gxa.common.ResponseData;
import com.gxa.common.Result;
import com.gxa.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SysUserController {

    @Autowired(required = false)
    private SysUserService sysUserService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData login(String username, String password){
        Subject subject = SecurityUtils.getSubject();
        if(!subject.isAuthenticated()){//认证
            //获取Token : 从前端传
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
            //登录
            subject.login(token);
            subject.checkRole("超级管理员");
        }
        return null;
    }
    @RequestMapping(value = "/findSysUserList",method = RequestMethod.GET)
    @ResponseBody
    public Result findSysUserList(Integer currentPage, Integer pageSize){
        return sysUserService.findSysUserList(currentPage,pageSize);
    }
}








